using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

/// CREDITS
// All models obtained from the following sites:
// http://create.msdn.com/en-US/education/catalog/?contenttype=0&devarea=4&platform=0&sort=1&lc=1033&p=1
// http://www.turbosquid.com/
//
//
// Some Code sampled from projects provided in tutorials and found at apphub (the first link above)
// sounds sampled from a variety of sites listed below.
/*
Http://awdpro.com/sound_effects.htm
Http://soundtrack.imphenzia.com/sound-effects
Http://www.3dmmstudio.co.uk/sounds.php
Http://www.royaltyfreemusic.com/sound-effects.html
Http://www.soundjay.com
Http://www.simplythebest.net
*/
/// END CREDITS
namespace FoodFight3D
{
     
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        
        //constants
        const float worldSize = 50f;
        const int worldSize2 = (int)worldSize;
        const int maxHoles = 10;
        const int maxFloorFoods = 10;
        const int pitSpacer = 15;
        const float chefScale = 0.1f;
        const float playerScale = .13f;
        const float rotationSpeed = .02f;
        const int attackSpeed = 50; //higher is slower
        const int moveSpeed = 200; //higher is slower
        const int maxThrowFoods = 60; 

        private Matrix view = Matrix.CreateLookAt(new Vector3(-60f, 15f, 60f), new Vector3(-45f, 10.1f, 45f), Vector3.UnitY);
        private Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 400f);

        private Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));

        //player
        public Kathy player;

        //camera
        public int camera = 3;

        //for chef attacks
        public int popUp = 0;
        public int doMove = 0;
        
        //health objects
        Texture2D mHealthBar;
        int mCurrentHealth = 200;
        
        //Camera controls
        public float cameraRotation;

        //Font
        SpriteFont Font;
        
        //Arrays of Objects
        public Holes[] pitArray = new Holes[maxHoles];
        public Foods[] foodsArray = new Foods[maxThrowFoods];
        public Foods[] floorFoodsArray = new Foods[maxFloorFoods];
        public Chef[] chefArray = new Chef[4];
        
        //Models
        Model iceCream;
        Model wall;
        Model ground;
        Model pizza;
        
        //to place holes not on top of each other
        int randomX;
        int randomZ;
        int randomFood;
        float scale;

        //Random
        Random random = new Random();

        //Sami's Variables
        bool collisionControl = false;
        public int winValue = 0;
        public int timer = 30;
        public bool playOnce = true;
        public static long milliseconds = 0;
        public AudioEngine audioEngine;
        public WaveBank waveBank;
        public SoundBank soundBank;
        public int index;
        public int pickedUpFoodPoints = 0;
        int j;
        public static long seconds = 0;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            //graphics.IsFullScreen = true;

        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            audioEngine = new AudioEngine("Content/mySound.xgs");
            waveBank = new WaveBank(audioEngine, "Content/Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, "Content/Sound Bank.xsb");
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            #region place holes, player, chef
            // TODO: use this.Content to load your game content here
            for (int i = 0; i < maxHoles; )
            {
                int min = 0 - worldSize2 + pitSpacer;
                int max = 0 + worldSize2 - pitSpacer;
                randomX = random.Next(min, max);
                randomZ = random.Next(min, max);

                for (int j = -1; j < i; j++)
                {
                    if (i > 0 && j >= 0)
                    {
                        double distance = Math.Sqrt((randomX - pitArray[j].position.X) * (randomX - pitArray[j].position.X)
                            + (randomZ - pitArray[j].position.Z) * (randomZ - pitArray[j].position.Z));
                        if (distance > (double)pitSpacer && j == (i - 1))
                        {
                            pitArray[i] = new Holes(Content.Load<Model>("Pit"), (float)randomX, -1f, (float)randomZ);
                            i++;
                            break;
                        }
                        else if (distance > (double)pitSpacer)
                        {
                        }
                        else
                            break;
                    }
                    else if (i == 0)
                    {
                        pitArray[i] = new Holes(Content.Load<Model>("Pit"), (float)randomX, -1f, (float)randomZ);
                        i++;
                        break;
                    }
                }
            }

            //player
            player = new Kathy(Content.Load<Model>("dude"), -45f, 0.1f, 45f);

            //chefs
            for (int i = 0; i < 4; )
            {
                randomX = random.Next(0, maxHoles - 1);

                for (int j = -1; j <= i; j++)
                {
                    if (j > -1 && j < i && i > 0)
                    {
                        if (chefArray[j].holeNum == randomX)
                            break;
                        else if (j == i - 1 || i == 0)
                        {
                            chefArray[i] = new Chef(Content.Load<Model>("dude"), pitArray[randomX].position.X, -100 * chefScale + 5,
                                pitArray[randomX].position.Z, randomX);
                            pitArray[randomX].occupied = true;
                            i++;
                        }
                    }
                    else if (j == -1 && i == 0)
                    {
                        chefArray[i] = new Chef(Content.Load<Model>("dude"), pitArray[randomX].position.X, -100 * chefScale + 5, 
                            pitArray[randomX].position.Z, randomX);
                        pitArray[randomX].occupied = true;
                        i++;
                    }
                }
            }
            #endregion

            #region foods

            pizza = Content.Load<Model>("pizza");

            #endregion

            #region Filling up floorFoodsArray


            for (int i = 0; i < maxFloorFoods;)
            {
                int min = 0 - worldSize2 + pitSpacer;
                int max = 0 + worldSize2 - pitSpacer;
                randomX = random.Next(min, max);
                randomZ = random.Next(min, max);
                randomFood = random.Next(0,3);

                for (int j = 0; j < maxHoles; j++)
                {
                    
                        double distance = Math.Sqrt((randomX - pitArray[j].position.X) * (randomX - pitArray[j].position.X)
                            + (randomZ - pitArray[j].position.Z) * (randomZ - pitArray[j].position.Z));
                        if (distance > ((double)pitSpacer * .66) && j == (maxHoles - 1))
                        {
                            for (int k = -1; k < i; k++)
                            {            
                                if (i > 0 && k >= 0)
                                {
                                    double distance2 = Math.Sqrt((randomX - floorFoodsArray[k].position.X) * (randomX - floorFoodsArray[k].position.X)
                                        + (randomZ - floorFoodsArray[k].position.Z) * (randomZ - floorFoodsArray[k].position.Z));
                                    if (distance2 > ((double)pitSpacer * .66) && k == (i - 1))
                                    {
                                        if (randomFood == 0)
                                        {
                                            floorFoodsArray[i] = new Foods(Content.Load<Model>("orange"), 5, randomX, 2f, randomZ);
                                        }
                                        else if (randomFood == 1)
                                        {
                                            floorFoodsArray[i] = new Foods(Content.Load<Model>("banana"), 7, randomX, 0.5f, randomZ);
                                        }
                                        else if (randomFood == 2)
                                        {
                                            floorFoodsArray[i] = new Foods(Content.Load<Model>("pizza"), 10, randomX, 0.5f, randomZ);
                                        }
                                        i++;
                                        break;
                                    }
                                    else if (distance2 > ((double)pitSpacer * .66))
                                    {
                                    }
                                    else
                                        break;
                                }
                                else if (i == 0)
                                {
                                    if (randomFood == 0)
                                    {
                                        floorFoodsArray[i] = new Foods(Content.Load<Model>("orange"), 5, randomX, 2f, randomZ);
                                    }
                                    else if (randomFood == 1)
                                    {
                                        floorFoodsArray[i] = new Foods(Content.Load<Model>("banana"), 7, randomX, 0.5f, randomZ);
                                    }
                                    else if (randomFood == 2)
                                    {
                                        floorFoodsArray[i] = new Foods(Content.Load<Model>("pizza"), 10, randomX, 0.5f, randomZ);
                                    }
                                    i++;
                                    break;
                                }
                            }
                            break;
                        }
                        else if (distance > ((double)pitSpacer * .66))
                        {
                        }
                        else
                            break;
                    
                    
                }
            }

            //floorFoodsArray[i] = new Foods(Content.Load<Model>("banana"), 10, 0f, 10f, 0f);
            
             
            #endregion

            #region throwable foods array

            for (int i = 0; i < maxThrowFoods; i++)
            {
                if (i >= 0 && i < (maxThrowFoods/6))
                    foodsArray[i] = new Foods(Content.Load<Model>("pizza"), 10, -60, 100, 0);
                if (i >= (maxThrowFoods / 6) && i < (maxThrowFoods / 2))
                    foodsArray[i] = new Foods(Content.Load<Model>("banana"), 7, -60, 100, 0);
                if (i >= (maxThrowFoods / 2) && i < maxThrowFoods)
                    foodsArray[i] = new Foods(Content.Load<Model>("orange"), 5, -60, 100, 0);
            }
            
            #endregion

            Font = Content.Load<SpriteFont>("Score");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Load the HealthBar image from the disk into the Texture2D object
            mHealthBar = Content.Load<Texture2D>("HealthBar3");

            #region ground and ice cream
            // Load the ground model
            ground = Content.Load<Model>("Ground");

            //load ice cream
            iceCream = Content.Load<Model>("icecream");
            //wall = Content.Load<Model>("wall");
            #endregion


            //pitArray[9] = new Holes(Content.Load<Model>("Pit"), 50f, -1f, -50f);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            
            KeyboardState keyboardState = Keyboard.GetState();
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||keyboardState.IsKeyDown(Keys.Escape))
                this.Exit();
            if (winValue == 0)
            {
                player.move();
            }

            #region if holding food, actions can be taken

            if (player.holdingFood)
            {
                if (keyboardState.IsKeyDown(Keys.C))
                {
                    player.Strength += floorFoodsArray[player.heldNum].Strength;
                    floorFoodsArray[player.heldNum].position.X = 500f;
                    floorFoodsArray[player.heldNum].position.Y = 50f;
                    floorFoodsArray[player.heldNum].position.Z = 500f;
                    player.holdingFood = false;
                    floorFoodsArray[player.heldNum].held = false;
                }

                if (keyboardState.IsKeyDown(Keys.Space))
                {
                    floorFoodsArray[player.heldNum].thrown = true;
                    float xAddition = (float)(Math.Sin((double)player.rotationAngle) * 1);
                    float zAddition = (float)(Math.Cos((double)player.rotationAngle) * 1);
                    float xCam = player.location.X + xAddition;
                    float zCam = player.location.Z + zAddition;
                    floorFoodsArray[player.heldNum].velocity = new Vector3(xAddition, 0, zAddition) * .8f;
                    soundBank.PlayCue("throw");
                    player.holdingFood = false;
                    floorFoodsArray[player.heldNum].held = false;
                }
            }

            #endregion

            #region update camera
            if (keyboardState.IsKeyDown(Keys.D1))
                camera = 1;
            else if (keyboardState.IsKeyDown(Keys.D3))
                camera = 3;

            if (camera == 3)
                moveCamera(keyboardState);
            #endregion

            #region update chefs

            if (winValue == 0)
            {
                for (int i = 0; i < 4; i++)
                {
                    popUp = random.Next(1, attackSpeed);
                    doMove = random.Next(1, moveSpeed);
                    int foodRandom = random.Next(0, maxThrowFoods);
                    chefArray[i].update(foodsArray, pitArray, player, soundBank, popUp, doMove, foodRandom);
                }
            }
            #endregion

            #region update thrown foods
            for (int i = 0; i < maxHoles*6; i++)
            {
                foodsArray[i].update(player);
            }
            #endregion

            #region update ground foods (in hand)
            
            for (int i = 0; i < maxFloorFoods; i++)
            {
                floorFoodsArray[i].update(player);
            }

            #endregion


            #region sami's code for health and collision
            //if (keyboardState.IsKeyDown(Keys.Up) == true)
            //{
            //    mCurrentHealth += 1;
            //}

            //If the Down Arrowis pressed, decrease the Health bar
            //if (keyboardState.IsKeyDown(Keys.Down) == true)
            //{
            //    mCurrentHealth -= 1;
            //}

            //Force the health to remain between 0 and 100
            player.Strength = (int)MathHelper.Clamp(player.Strength, 0, 2000);
            // TODO: Add your update logic here

            
            if (collideWithHole())
            {
                if (!collisionControl)
                {
                    player.Strength -= 25;
                    collisionControl = true;
                    soundBank.PlayCue("boing");
                }
            }
            if (collideWithIceCream())
            {
                winValue = 1;
            }

            milliseconds += (long)gameTime.ElapsedGameTime.TotalMilliseconds;
            //seconds += (long)gameTime.ElapsedGameTime.TotalMilliseconds;
            // The time since Update was called last.
            //if (seconds >= 3000)
            //{
            //    moveChef();
            //    seconds = 0;
            //}

            if (winValue == 0)
            {
                if (milliseconds >= 1000)
                {
                    milliseconds = 0;
                    timer -= 1;
                }

            }

            if (collideWithFoodOnFloor() && !player.holdingFood)
            {
                soundBank.PlayCue("Coin");
                //floorFoodsArray[index].position.X = 500f;
                //floorFoodsArray[index].position.Y = 50f;
                //floorFoodsArray[index].position.Z = 500f;
                floorFoodsArray[index].held = true;
                player.holdingFood = true;
                player.heldNum = index;
                //player.Strength += floorFoodsArray[index].Strength;
                //pickedUpFoodPoints += floorFoodsArray[index].Strength;
            }

            if (collideWithThrownFood())
            {
                soundBank.PlayCue("slap_2");
                foodsArray[index].position.X = 500f;
                foodsArray[index].position.Y = 50f;
                foodsArray[index].position.Z = 500f;
                player.Strength -= foodsArray[index].Strength;
                //pickedUpFoodPoints -= foodsArray[index].Strength;
            }
            #endregion
            base.Update(gameTime);
        }

        /*public void moveChef()
        {
            for (int i = 0; i < 4; i++)
            {
                j = random.Next(0,9); 
                chefArray[i].location = pitArray[j].position;
            }
        }*/

        /// <summary>
        /// Moves the camera around the player as per the player's input
        /// </summary>
        /// <param name="keyboard"></param>
        public void moveCamera(KeyboardState keyboard)
        {
            if (keyboard.IsKeyDown(Keys.Right))
            {
                cameraRotation -= .02f;
            }
            if (keyboard.IsKeyDown(Keys.Left))
            {
                cameraRotation += .02f;
            }
        }

        #region collision methods
        public bool collideWithHole()
        {
            for (int i = 0; i < maxHoles; i++)
            {
                if (pitArray[i].position.X - 2 < player.location.X && pitArray[i].position.X + 2 > player.location.X
                    && pitArray[i].position.Z - 2 < player.location.Z && pitArray[i].position.Z + 2 > player.location.Z)
                {
                    
                    return true;                 
                }
            }
            collisionControl = false;
            return false;
        }

        public bool collideWithIceCream()
        {
            if (player.location.X - 2 < 45 && player.location.X + 2 > 45
                    && player.location.Z - 2 < -45 && player.location.Z + 2 > -45)
            {

                return true;                 
            }
            return false;
        }

        public bool collideWithFoodOnFloor()
        {
            for (int i = 0; i < maxFloorFoods; i++)
            {
                if (player.location.X - 2 < floorFoodsArray[i].position.X && player.location.X + 2 > floorFoodsArray[i].position.X
                        && player.location.Z - 2 < floorFoodsArray[i].position.Z && player.location.Z + 2 > floorFoodsArray[i].position.Z)
                {
                    index = i;
                    return true;
                }
            }
            return false;
        }
        public bool collideWithThrownFood()
        {
            for (int i = 0; i < maxThrowFoods; i++)
            {
                if (player.location.X - 3 < foodsArray[i].position.X && player.location.X + 3 > foodsArray[i].position.X
                        && player.location.Z - 3 < foodsArray[i].position.Z && player.location.Z + 3 > foodsArray[i].position.Z)
                {
                    index = i;
                    return true;
                }
            }
            return false;
        }

        #endregion 
       
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (camera == 3)
            {
                float xAddition = (float)(Math.Sin((double)player.rotationAngle + (double)cameraRotation) * 21.213);
                float zAddition = (float)(Math.Cos((double)player.rotationAngle + (double)cameraRotation) * 21.213);
                float xCam = player.location.X - xAddition;
                float zCam = player.location.Z - zAddition;
                view = Matrix.CreateLookAt(new Vector3(xCam, 15f, zCam), new Vector3(player.location.X, 11f, player.location.Z), Vector3.UnitY);
            }
            else if (camera == 1)
            {
                float xAddition = (float)(Math.Sin((double)player.rotationAngle + (double)cameraRotation) * 1);
                float zAddition = (float)(Math.Cos((double)player.rotationAngle + (double)cameraRotation) * 1);
                float xCam = player.location.X - xAddition;
                float zCam = player.location.Z - zAddition;
                view = Matrix.CreateLookAt(new Vector3(xCam, 13f, zCam),
                       new Vector3(player.location.X + (player.location.X - xCam), 12.5f, player.location.Z + (player.location.Z - zCam)), Vector3.UnitY);
            }



            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Set our sampler state to allow the ground to have a repeated texture
            GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

            // Draw the ground scaled to our world
            ground.Draw(Matrix.CreateScale(worldSize, 1f, worldSize), view, projection);

            //draw ice cream
            drawModel(iceCream);
            
            //draw player
            world = Matrix.CreateScale(playerScale) * Matrix.CreateRotationY(player.rotationAngle) * Matrix.CreateTranslation(player.location);
            player.draw(world, view, projection);

            #region draw pits
            for (int i = 0; i < maxHoles; i++)
            {
                world = Matrix.CreateScale(4f) * Matrix.CreateTranslation(pitArray[i].position);
                pitArray[i].draw(world, view, projection);
            }
            #endregion

            #region draw chefs
            if (winValue == 0)
            {
                for (int i = 0; i < 4; i++)
                {
                    world = Matrix.CreateScale(chefScale) * Matrix.CreateRotationY(chefArray[i].rotationAngle) * Matrix.CreateTranslation(chefArray[i].location);
                    chefArray[i].draw(world, view, projection);
                }
            }
            #endregion

            #region draw floor food

            for (int i = 0; i < maxFloorFoods; i++)
            {
                if (floorFoodsArray[i].Strength == 5)
                {
                    scale = .02f;
                }
                else if (floorFoodsArray[i].Strength == 7)
                {
                    scale = .8f;
                }
                else if (floorFoodsArray[i].Strength == 10)
                {
                    scale = .5f;
                }
                world = Matrix.CreateScale(scale) * Matrix.CreateRotationY(floorFoodsArray[i].rotationAngle)
                        * Matrix.CreateTranslation(floorFoodsArray[i].position);
                floorFoodsArray[i].draw(world, view, projection);
                if (scale == .5f)
                {
                    world = Matrix.CreateScale(scale) * Matrix.CreateRotationY(MathHelper.ToRadians(180))
                            * Matrix.CreateTranslation(floorFoodsArray[i].position);
                    drawModel(pizza, world);
                }

            }

            #endregion

            #region draw throwing foods

            if (winValue == 0)
            {
                for (int i = 0; i < maxThrowFoods; i++)
                {
                    if (foodsArray[i].Strength == 5)
                    {
                        scale = .02f;
                    }
                    else if (foodsArray[i].Strength == 7)
                    {
                        scale = .8f;
                    }
                    else if (foodsArray[i].Strength == 10)
                    {
                        scale = .5f;
                    }
                    world = Matrix.CreateScale(scale) * Matrix.CreateRotationY(foodsArray[i].rotationAngle)
                            * Matrix.CreateTranslation(foodsArray[i].position);
                    foodsArray[i].draw(world, view, projection);
                    if (scale == .5f)
                    {
                        world = Matrix.CreateScale(scale) * Matrix.CreateRotationY(MathHelper.ToRadians(180))
                                * Matrix.CreateTranslation(foodsArray[i].position);
                        drawModel(pizza, world);
                    }
                }
            }
            #endregion


            #region spritebatch for HUD
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, 
                DepthStencilState.Default, RasterizerState.CullCounterClockwise);

            if (winValue == 1)
            {
                spriteBatch.DrawString(Font, " Congratulation! You have Won!", new Vector2(this.Window.ClientBounds.Width / 2 - 110, this.Window.ClientBounds.Height / 2 - 100), Color.Red);
                if (playOnce)
                {
                    soundBank.PlayCue("win");
                    playOnce = false;
                }
            } 
            if (timer <= 0 || player.Strength <= 0 || winValue == -1)
            {
                if (playOnce)
                {
                    soundBank.PlayCue("lose");
                    playOnce = false;
                }
                spriteBatch.DrawString(Font, " Sorry! You have Lost!", new Vector2(this.Window.ClientBounds.Width / 2 - 80, this.Window.ClientBounds.Height / 2 - 100), Color.Red);
                winValue = -1;
            }

            /*for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(pitArray[i].position);
                Console.WriteLine("");
                if (i <4)
                    Console.WriteLine(chefArray[i].location);
            }*/

            //Draw the negative space for the health bar
            spriteBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width / 2 - mHealthBar.Width / 2, 30, mHealthBar.Width, 21), new Rectangle(0, 45, mHealthBar.Width, 21), Color.Gray);

            //Draw the current health level based on the current Health
            spriteBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width / 2 - mHealthBar.Width / 2, 30, (int)(mHealthBar.Width * ((double)player.Strength / (player.Strength))), 21), new Rectangle(0, 45, mHealthBar.Width, 21), Color.Red);

            //Draw the box around the health bar
            spriteBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width / 2 - mHealthBar.Width / 2, 30, mHealthBar.Width, 25), new Rectangle(0, 0, mHealthBar.Width, 25), Color.White);

            spriteBatch.DrawString(Font, "Health: " + player.Strength, new Vector2(this.Window.ClientBounds.Width / 2 - 40, 32), Color.Black);


            //Draw the negative space for the health bar
            spriteBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width / 2 - mHealthBar.Width / 2, 60, mHealthBar.Width, 21), new Rectangle(0, 45, mHealthBar.Width, 21), Color.Gray);

            //Draw the current health level based on the current Health
            spriteBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width / 2 - mHealthBar.Width / 2, 60, (int)(mHealthBar.Width * ((double)timer / 40)), 21), new Rectangle(0, 45, mHealthBar.Width, 21), Color.Green);

            //Draw the box around the health bar
            spriteBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width / 2 - mHealthBar.Width / 2, 60, mHealthBar.Width, 25), new Rectangle(0, 0, mHealthBar.Width, 25), Color.White);

            spriteBatch.DrawString(Font, "Time: " + timer, new Vector2(this.Window.ClientBounds.Width / 2 - 40, 62), Color.Black);


            spriteBatch.End();
            #endregion

            base.Draw(gameTime);
        }

        public void drawModel(Model model)
        {
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World =
                        Matrix.CreateRotationX(MathHelper.ToRadians(-90))
                        * Matrix.CreateScale(.7f, .7f, .7f)
                        * Matrix.CreateTranslation(45f, 0f, -45f);
                    effect.View = view;
                    effect.Projection = projection;
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }

        public void drawModel(Model model, Matrix world)
        {
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = mesh.ParentBone.Transform * world;
                    effect.View = view;
                    effect.AmbientLightColor = new Vector3(1f, 1f, 0f);  // for bananas!
                    effect.Projection = projection;
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }

        
    }
}
